<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button @click="showChild">显示子组件</button>
      <child v-show="type" @changetype="changeShow"></child>
    </div>
    <script src="./vue.js"></script>
    <script>
      let child = {
        template: `
          <div>
            我是子组件
            <button @click="change">点击隐藏子组件</button>
          </div>
        `,
        methods: {
          change() {
            this.$emit("changetype", false);
          },
        },
      };

      let app = new Vue({
        el: "#app",
        data: {
          type: false,
        },
        components: {
          child,
        },
        methods: {
          showChild() {
            this.type = true;
          },
          changeShow(data) {
            this.type = data;
          },
        },
      });
    </script>
  </body>
</html>
